<template>
  <div class="mv-container">
    <div class="mv-wrap">
      <h3 class="title">{{mvName}}</h3>
      <!-- mv -->
      <div class="video-wrap">
        <video controls :src="url"></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class="avatar-wrap">
            <img :src="cover" alt="" />
          </div>
          <span class="name" v-for="(item,index) in artists" :key="index">
          {{item.name}}
          <p style="display: inline-block;width: 3px;height: 10px;"></p>
          </span>
          
        </div>
        <div class="mv-info">
          <h2 class="title">{{briefDesc}}</h2>
          <span class="date">发布：{{publishTime}}</span>
          <span class="number">播放：{{playCount}}次</span>
          <p class="desc">
            {{desc}}
          </p>
        </div>
      </div>
      <!-- 精彩评论 -->
      <div class="comment-wrap">
        <p class="title">精彩评论<span class="number">({{hotComments.length}})</span></p>
        <div class="comments-wrap">
          <div class="item" v-for="(item,index) in hotComments" :key="index">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="hotReps[0]" v-for="(rep,i) in item.beReplied" :key="i">
                <span class="name">{{rep.user.nickname}}：</span>
                <span class="comment">{{rep.content}}</span>
              </div>
              <div class="date">{{item.time | dateString('YYYY-MM-DD HH:mm:ss')}}</div>
            </div>
          </div>
          <div class="content empty" v-if="hotComments.length==0">暂时还没有热门评论哦！</div>
        </div>
        
      </div>
      <!-- 最新评论 -->
      <div class="comment-wrap">
        <p class="title">最新评论<span class="number">({{total-hotComments.length}})</span></p>
        <div class="comments-wrap">
          <div class="item" v-for="(item,index) in comments" :key="index">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="reps[0]" v-for="(rep,i) in item.beReplied" :key="i">
                <span class="name">{{rep.user.nickname}}：</span>
                <span class="comment">{{rep.content}}</span>
              </div>
              <div class="date">{{item.time | dateString('YYYY-MM-DD HH:mm:ss')}}</div>
            </div>
          </div>
          <div class="content empty" v-if="total==0">一个评论都没有！</div>
        </div>
      </div>
      <!-- 分页器 -->
      <el-pagination
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="page"
        :page-size="20"
        :limit="limit"
      >
      </el-pagination>
    </div>
    <!-- 相关mv -->
    <div class="mv-recommend">
      <h3 class="title">相关推荐</h3>
      <div class="mvs">
        <div class="items">
          <div class="item" v-for="(item,index) in mvs" :key="index" @click="toMv(item.id)">
            <div class="img-wrap">
              <img :src="item.cover" alt="" />
              <span class="iconfont icon-play"></span>
              <div class="num-wrap">
                <div class="iconfont icon-play"></div>
                <div class="num">{{item.playCount>100000?parseInt(item.playCount/10000)+'w':item.playCount}}</div>
              </div>
              <span class="time">{{item.duration}}</span>
            </div>
            <div class="info-wrap">
              <div class="name">{{item.name}}</div>
              <div class="singer">{{item.artistName}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import axios from 'axios'
  import moment from 'moment'
export default {
  name: 'mv',
  data() {
    return {
      // 总条数
      total: 20,
      // 页码
      page: 1,
      // 页容量
      limit: 20,
      url:'', //mv在线播放地址
      artists:[], //歌手
      briefDesc:'', //描述摘要
      desc:'', //描述
      cover:'', //歌手头像
      mvName:'', //歌名
      publishTime:'', //发布时间
      playCount:'', //播放次数
      mvs:[], //推荐mv
      comments:[], //普通评论
      reps:[], //普通回复
      hotComments:[], //热门评论
      hotReps:[], //热门回复
    };
  },
  filters:{
    dateString(val,format){
      return moment(val).format(format)
    }
  },
  created() {
    this.playMv() //播放mv
    this.mvDetail() //mv信息
    this.mvRecommend() //mv推荐
    this.comment() //评论区

    
  },
  methods: {
    // 跳转到推荐的mv
    toMv(id) {
      this.$router.push(`/mv?q=${id}`);
      this.playMv() //播放mv
      this.mvDetail() //mv信息
      this.mvRecommend() //mv推荐
      this.comment() //评论区
    },
    // 翻页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.page=val
      this.comment()
    },
    // 播放mv
    playMv(){
      axios({
        url:'https://autumnfish.cn/mv/url',
        method:'get',
        params:{
          id:this.$route.query.q
        }
      }).then(res=>{
        console.log('mv地址',res)
        this.url=res.data.data.url
        if(res.data.data.msg=="版权方要求，当前资源需单独付费使用"){
          this.$message.warning('该资源无版权')
        }
      })
    },
    // mv信息
    mvDetail(){
      axios({
        url:'https://autumnfish.cn/mv/detail',
        method:'get',
        params:{
          mvid:this.$route.query.q
        }
      }).then(res=>{
        console.log('mv信息',res)
        this.artists=res.data.data.artists //歌手
        this.briefDesc=res.data.data.briefDesc //描述摘要
        this.desc=res.data.data.desc //描述
        this.cover=res.data.data.cover //歌手头像
        this.mvName=res.data.data.name //歌名
        this.publishTime=res.data.data.publishTime //发布时间
        this.playCount=res.data.data.playCount //播放次数this
      })
    },
    // mv推荐
    mvRecommend(){
      axios({
        url:'https://autumnfish.cn/simi/mv',
        method:'get',
        params:{
          mvid:this.$route.query.q
        }
      }).then(res=>{
        console.log('mv推荐',res)
        this.mvs=res.data.mvs
        for (var i = 0; i < this.mvs.length; i++) {
          let time = moment.duration(this.mvs[i].duration)
          let seconds = time._data.seconds > 9 ? time._data.seconds : '0' + time._data.seconds
          this.mvs[i].duration = `${time._data.minutes}:${seconds}`
        }
      })
    },
    // 评论区
    comment(){
      axios({
        url:'https://autumnfish.cn/comment/mv',
        method:'get',
        params:{
          id:this.$route.query.q,
          limit:20,
          offset:(this.page-1)*20
        }
      }).then(res=>{
        console.log('评论',res)
        
        
        if(res.data.hotComments){
          this.hotComments=res.data.hotComments
          for(let i=0;i<this.hotComments.length;i++){
            this.hotReps=this.hotComments[i].beReplied
          }
        }
        if(res.data.comments){
          this.comments=res.data.comments
          for(let i=0;i<this.comments.length;i++){
            this.reps=this.comments[i].beReplied
          }
        }
        this.total=res.data.total
      })
    }
  }
};
</script>

<style>
  .empty{
    font-size: 20px;
    padding-top: 5px;
  }
</style>
